package keeto.com.vn.classfied.model;

import java.io.Serializable;

import keeto.com.vn.classified.config.IConstant;

import android.content.Context;


/**
 * @author hector <br/>
 *         Created on 2012-4-17
 * 
 */
public class CommentUIModel implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8045422813943081154L;
	public static final int TYPE_COMMENT = 1;
	public static final int TYPE_REPLY = 2;

	
	
	public CommentUIModel(int commentType, String id, String postId,
			UserUIModel from, String message, long createTime,
			boolean ownedByYou) {
		super();
		this.commentType = commentType;
		this.commentId = id;
		this.setPostId(postId);
		this.from = from;
		this.message = message;
		this.createTime = createTime;
		this.ownedByYou = ownedByYou;
	}
	
	public CommentUIModel(){
		
	}

	/*
	 * comment type is for click action, to separate the comment and reply comment.
	 */
	private int commentType = TYPE_COMMENT;

	/**
	 * Comment globe id
	 */
	private String commentId = IConstant.UNINITIALIZED_STRING;
	
	private String postId = IConstant.UNINITIALIZED_STRING;
	
	/**
	 * The user who created  or reply the comment
	 */
	private UserUIModel from = null;
	
	/**
	 * The Comment which be replyed is type is reply type
	 */
	private CommentUIModel replyComment = null;
	/**
	 * The comment text
	 */
	private String message = IConstant.UNINITIALIZED_STRING;
	/**
	 * The timestamp the comment was created
	 */
	private long createTime = IConstant.UNINITIALIZED_LONG;

	

	public CommentUIModel getReplyComment() {
		return replyComment;
	}

	public void setReplyComment(CommentUIModel replyComment) {
		this.replyComment = replyComment;
	}

	private transient CharSequence formatedMessage = null;
	/**
	 * 
	 * Indicate whether the viewer owns the comment
	 */
	private boolean ownedByYou = false;
	
	private String postMessage = IConstant.UNINITIALIZED_STRING;
	
	private transient CharSequence formatedPostMessage = null;

	

	public CharSequence getFormatedPostMessage(ClickSpan.OnClickListener listener,
			Context context) {
		if (formatedPostMessage == null) {
			formatedPostMessage = ClickSpanParser.getSnsClickify(postMessage, listener);
//			formatedPostMessage = SmileyParser.getInstance(context).parseToSmiley(
//					formatedPostMessage);
		}
		return formatedPostMessage;
	}

	public String getPostMessage() {
		return postMessage;
	}

	public void setPostMessage(String postMessage) {
		this.postMessage = postMessage;
	}

	

	public String getCommentId() {
		return commentId;
	}

	public void setCommentId(String commentId) {
		this.commentId = commentId;
	}

	public UserUIModel getFrom() {
		return from;
	}

	public void setFrom(UserUIModel from) {
		this.from = from;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public CharSequence getFormatedMessage(ClickSpan.OnClickListener listener,
			Context context) {
		if (formatedMessage == null) {
			formatedMessage = ClickSpanParser.getSnsClickify(message, listener);
//			formatedMessage = SmileyParser.getInstance(context).parseToSmiley(
//					formatedMessage);
		}
		return formatedMessage;
	}

	public CharSequence getFormatedMessage(String prefix,
			ClickSpan.OnClickListener listener) {
		if (formatedMessage == null) {
			formatedMessage = ClickSpanParser.getSnsClickify(prefix + message,
					listener);
		}
		return formatedMessage;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public boolean isOwnedByYou() {
		return ownedByYou;
	}

	public void setOwnedByYou(boolean ownedByYou) {
		this.ownedByYou = ownedByYou;
	}

	public int getCommentType() {
		return commentType;
	}

	public void setCommentType(int commentType) {
		this.commentType = commentType;
	}

	public String getPostId() {
		return postId;
	}

	public void setPostId(String postId) {
		this.postId = postId;
	}
	
}
